package studyStream;

import enity.Person;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class TestStream {
    @Test
    public void Test01(){
        Arrays.asList("a","b","c","d","f").stream().forEach(System.out::println);//循环打印
    }

    //过滤内容
    @Test
    public void Test02(){
        Arrays.asList("aa","qaw","ad","ia","ids").stream().filter((String p)->p.contains("a")).forEach(System.out::println);//保留结果为真的数据
    }

    //去重
    @Test
    public void test03(){
        Arrays.asList("aa","ab","aa","ab","","s").stream().distinct().forEach(System.out::println);
    }
     //排序
    @Test
    public void test04(){
        Arrays.asList(11,21,1,3,2,12,12312,23,0).stream().sorted().forEach(System.out::println);
    }
    //自定义排序
    @Test
    public void test05(){
        List<Person> list=new ArrayList<>();
        /*list.add(new Person("李铭晗",22,"男"));
        list.add(new Person("张伟",18,"男"));
        list.add(new Person("刘备",20,"男"));
        list.add(new Person("诸葛亮",58,"男"));
        list.add(new Person("李秋",29,"男"));*/
        list.stream().sorted((p1,p2)->p1.getAge()-p2.getAge()).forEach(System.out::println);
    }

    //map
    @Test
    public void test06(){
       List<Integer> numbers= Arrays.asList(1,2,3,5,6).stream().map(i->i*i).collect(Collectors.toList());
        for (Integer temp:numbers) {
            System.out.println(temp);
        }
    }
}
